# 03-图书管理系统.py
 
'''
 查询图书
 显示库存
 添加图书
 修改图书库存
 退出
 list 二维列表 列表字典(json)
'''
list  = [{
   "ref":'10086',
   'book_name':'Photoshop从入门到',
   'pbs_date':'2023-03-09',
   'price':99.9,
   "inventory":5
},{
   "ref":'10010',
   'book_name':'SSM轻量级空间应用实战',
   'pbs_date':'2015-10-09',
   'price':99.9,
   "inventory":5
},{
   "ref":'10000',
   'book_name':'python开发基础',
   'pbs_date':'2019-03-09',
   'price':59.8,
   "inventory":5
}]


# 显示数目信息
def book_info(list):
   print('============================================================')
   print('编号',"\t\t\t","书名","\t\t","出版时间","\t","价格")
   for j in list:
       print(j['ref'],"\t",j['book_name'],"\t",j['pbs_date'],"\t",j['price'])
   print('============================================================')
# 显示库存
def in_info(list):
   print('====================================================')
   print('书号',"\t\t\t","书名","\t\t","库存")
   for j in list:
       print(j['ref'],"\t",j['book_name'],"\t",j['inventory'])
   print('====================================================')
# 新增图书
def add_book(list):
   ref= input('请输入编号：')
   book_name = input('请输入书名：')
   pbs_date = input('请输入出版时间：')
   price = float(input('请输入价格：'))
   list.append({"ref":ref,"book_name":book_name,"pbs_date":pbs_date,"price":price,"inventory":1})
# 修改
def update_book(list):
   id = input('请输入书号')
   up_inventory = int(input("请输入库存："))
   # 根据输入的书号判断是哪本书
   for x in list:
      if x['ref']==id:
         x['inventory']=up_inventory
      else:
         print('没有该图书！')  
# 主函数
def info(list):
    while True:
      print('====================')
      print('图书库存管理系统V0.1')
      print('1.显示书目信息')
      print('2.显示图书库存信息')
      print('3.添加数目信息')
      print('4.修改图书库存')
      print('5.退出')
      print('====================')
      index= int(input('请输入要执行的操作(填写数字):'))
      if index==5: break;
      if index==1: book_info(list)
      if index==3: add_book(list)
      if index==4:update_book(list)
      if index==2:in_info(list)
info(list)